#include <stdio.h>
#include <iostream>
#include<iomanip>
using namespace std;
struct student
{
    int accept;
    int score;
    char name[20];
}stu[1000];
int main()
{
    int n,m,score,i,j,k,t=0;
    scanf("%d%d",&n,&m);
    while (scanf("%s",stu[t].name)!=EOF)
    {
        stu[t].score=0;
        int ac=n;
        for (k=0;k<n;k++)
        {
            char data[10];
            int s=0;
            scanf("%s",data);
            for (i=0;i<strlen(data);i++)
            {
                if (data[i]=='-' || data[0]=='0')
                {
                    ac--;
                    break;
                }
                if (data[i]=='(')
                {
                    int s2=0;
                    for (j=i+1;j<strlen(data);j++)
                    {
                        if (data[j]==')')break;
                        s2=s2*10+data[j]-'0';
                    }
                    s=s+s2*m;
                    break;
                }
                s=s*10+data[i]-'0';
            }
            stu[t].score+=s;
        }
        stu[t].accept=ac;
        t++;
    }
    for (i=0;i<t;i++)
    for (j=i+1;j<t;j++)
    {
        if (stu[i].accept<stu[j].accept || (stu[i].accept==stu[j].accept&&stu[i].score>stu[j].score) || (stu

[i].accept==stu[j].accept&&stu[i].score==stu[j].score&&strcmp(stu[i].name,stu[j].name)>0))
        {
            char temp[20];
            strcpy(temp,stu[i].name);
            strcpy(stu[i].name,stu[j].name);
            strcpy(stu[j].name,temp);
            int temp2=stu[i].score;
            stu[i].score=stu[j].score;
            stu[j].score=temp2;
            temp2=stu[i].accept;
            stu[i].accept=stu[j].accept;
            stu[j].accept=temp2;
        }
    }
    for (i=0;i<t;i++)
    {
        cout<<stu[i].name;
        for (j=0;j<10-strlen(stu[i].name);j++)cout<<' ';
        cout<<' '<<setw(2)<<stu[i].accept<<' '<<setw(4)<<stu[i].score<<endl;
    }
    return 0;
}
